package spring.core.examples.java.configuration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.Profile;

import spring.core.examples.xml.Person;

/**
 * Demonstrates how to configure Spring context using Java classes. Note that
 * all beans configured in this configuration are singleton!
 */
@Configuration
@ImportResource("classpath:/my-properties.xml")
@Profile("production")
public class PersonConfiguration {

	/**
	 * Demonstrates how to mix definitions made in a XML configuration file with
	 * Java based configurtion
	 */
	private @Value("${person.firstname}")
	String firstName;
	private @Value("${person.name}")
	String name;
	private @Value("${person.age}")
	Integer age;

	/**
	 * Beate.
	 * 
	 * @return the person
	 */
	@Bean
	public Person beate() {
		Person myResult = new Person();
		myResult.setFirstName("Beate");
		myResult.setName("Elegant");
		myResult.setAge(5);
		return myResult;
	}

	/**
	 * Elke.
	 * 
	 * @return the person
	 */
	@Bean
	public Person elke() {
		Person myResult = new Person();
		myResult.setFirstName("Elke");
		myResult.setName("Elegant");
		myResult.setAge(45);
		myResult.addChild(beate());
		myResult.addChild(lea());
		return myResult;
	}

	/**
	 * Harry.
	 * 
	 * @return the person
	 */
	@Bean
	public Person harry() {
		Person myResult = new Person();
		myResult.setFirstName("Harry");
		myResult.setName("Hurtig");
		myResult.setAge(52);
		return myResult;
	}

	/**
	 * Hein.
	 * 
	 * @return the person
	 */
	@Bean
	public Person hein() {
		Person myResult = new Person();
		myResult.setFirstName(firstName);
		myResult.setName(name);
		myResult.setAge(age);
		return myResult;
	}

	/**
	 * Lea.
	 * 
	 * @return the person
	 */
	@Bean
	public Person lea() {
		Person myResult = new Person();
		myResult.setFirstName("Lea");
		myResult.setName("Elegant");
		myResult.setAge(3);
		return myResult;
	}

}
